package cn.biplam.front.component.data.common;

import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.template.base.Button;
import cn.biplam.front.template.base.Button.Button_Type;

/**
 * 按钮数据组件
 * @author XiaoRuxing
 * @create下午05:09:29
 * @version 1.0
 */
public class ButtonComp {

	/**
	 * 获取指定标题代码的按钮
	 * @param mUser       用户
	 * @param sButtonCode 按钮标题代码
	 * @return 指定标题代码的按钮
	 * @throws ErrorMessage
	 */
	public static HtmlWindow get(UserInfo mUser,String sButtonCode) throws ErrorMessage{
		return new Button(getCaption(mUser, sButtonCode)).get();
	}
	
	/**
	 * 获取指定标题代码的按钮
	 * @param mUser       用户
	 * @param sButtonCode 按钮标题代码
	 * @param buttonType  按钮类型
	 * @return 指定标题代码的按钮
	 * @throws ErrorMessage
	 */
	public static HtmlWindow get(UserInfo mUser,String sButtonCode,Button_Type buttonType) throws ErrorMessage{
		return new Button(null,getCaption(mUser, sButtonCode),buttonType).get();
	}
	
	/**
	 * 获取指定标题代码的按钮
	 * @param mUser       用户
	 * @param sButtonCode 按钮标题代码
	 * @param isClick  是否可以点击
	 * @return 指定标题代码的按钮
	 * @throws ErrorMessage
	 */
	public static HtmlWindow get(UserInfo mUser,String sButtonCode,boolean isClick) throws ErrorMessage{
		Button_Type buttonType;
		if(isClick){
			buttonType = Button_Type.Click;
		}else{
			buttonType = Button_Type.ReadOnly;
		}
		return get(mUser, sButtonCode, buttonType);
	}
	
	/**
	 * 获取指定标题代码的按钮
	 * @param buttonId   按钮页面ID
	 * @param mUser       用户
	 * @param sButtonCode 按钮标题代码
	 * @param buttonType  按钮类型
	 * @return 指定标题代码的按钮
	 * @throws ErrorMessage
	 */
	public static HtmlWindow get(String buttonId,UserInfo mUser,String sButtonCode,Button_Type buttonType) throws ErrorMessage{
		return new Button(buttonId,getCaption(mUser, sButtonCode),buttonType).get();
	}
	
	/**
	 * 获取指定标题代码的按钮
	 * @param buttonId   按钮页面ID
	 * @param mUser       用户
	 * @param sButtonCode 按钮标题代码
	 * @param script  按钮绑定脚本
	 * @return 指定标题代码的按钮
	 * @throws ErrorMessage
	 */
	public static HtmlWindow get(String buttonId,UserInfo mUser,String sButtonCode,String script) throws ErrorMessage{
		Button bt = new Button(buttonId,getCaption(mUser, sButtonCode),script);
		return bt.get();
	}
	
	/**
	 * 获取标题
	 * @param mUser        用户
	 * @param sButtonCode  按钮标题代码
	 * @return             按钮标题
	 * @throws ErrorMessage
	 */
	private static String getCaption(UserInfo mUser,String sButtonCode) throws ErrorMessage{
		String caption = CaptionComp.get(mUser, sButtonCode);
		if(TOOLS.StringIsEmpty(caption)){
			caption = sButtonCode;
		}
		return caption;
	}
}
